// app/evcp/menu-list/page.tsx

import { Suspense } from "react";
import { Card, CardContent } from "@/components/ui/card";
import { getActiveUsers, getMenuAssignments } from "@/lib/menu-list/servcie";
import { InitializeButton } from "@/lib/menu-list/table/initialize-button";
import { MenuListTable } from "@/lib/menu-list/table/menu-list-table";
import { Shell } from "@/components/shell"
import * as React from "react"
import { InformationButton } from "@/components/information/information-button";
import { useTranslation } from "@/i18n";
interface MenuListPageProps {
  params: Promise<{ lng: string }>
}

export default async function MenuListPage({ params }: MenuListPageProps) {
  const { lng } = await params
  const { t } = await useTranslation(lng, 'menu')
  
  // 초기 데이터 로드
  const [menusResult, usersResult] = await Promise.all([
    getMenuAssignments(),
    getActiveUsers()
  ]);

  // 서버사이드에서 번역된 메뉴 데이터 생성
  const translatedMenus = menusResult.data?.map(menu => ({
    ...menu,
    sectionTitle: menu.sectionTitle || "",
    translatedMenuTitle: t(menu.menuTitle || ""),
    translatedSectionTitle: t(menu.sectionTitle || ""),
    translatedMenuGroup: menu.menuGroup ? t(menu.menuGroup) : null,
    translatedMenuDescription: menu.menuDescription ? t(menu.menuDescription) : null
  })) || [];

  return (
    <Shell className="gap-2">
      <div className="flex items-center justify-between space-y-2">
        <div className="flex items-center justify-between space-y-2">
          <div>
            <div className="flex items-center gap-2">
              <h2 className="text-2xl font-bold tracking-tight">
                {t('menu.information_system.menu_list')}
              </h2>
              <InformationButton pagePath="evcp/menu-list" />
            </div>
            {/* <p className="text-muted-foreground">
              각 메뉴별로 담당자를 지정하고 관리할 수 있습니다.
            </p> */}
          </div>
        </div>

      </div>


      <React.Suspense
        fallback={
         ""
        }
      >
        <Card>
          <CardContent className="pt-6">
            <Suspense fallback={<div className="text-center py-8">로딩 중...</div>}>
              <MenuListTable
                initialMenus={translatedMenus}
                initialUsers={usersResult.data || []}
              />
            </Suspense>
          </CardContent>
        </Card>
      </React.Suspense>
    </Shell>

  );
}
